﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.ComponentModel.DataAnnotations;
using WalkingTec.Mvvm.Core;
using WalkingTec.Mvvm.Core.Extensions;
using TyMES.Model.BaseInformation;
using TyMES.Model;

namespace TyMES.ViewModel.BaseInformation.ProductVMs
{
    public partial class ProductListVM : BasePagedListVM<Product_View, ProductSearcher>
    {
        
        protected override IEnumerable<IGridColumn<Product_View>> InitGridHeader()
        {
            return new List<GridColumn<Product_View>>{
                
                this.MakeGridHeader(x => x.Product_ProductCode).SetTitle(@Localizer["Page.产品编码"].Value),
                this.MakeGridHeader(x => x.Product_ProductName).SetTitle(@Localizer["Page.产品名称"].Value),
                this.MakeGridHeader(x => x.Product_ProductVersion).SetTitle(@Localizer["Page.产品版本"].Value),
                this.MakeGridHeader(x => x.Product_Product_Type).SetTitle(@Localizer["Page.产品类型"].Value),
                this.MakeGridHeader(x => x.Product_IsVulnerable).SetTitle(@Localizer["Page.是否易损"].Value),
                this.MakeGridHeader(x => x.Product_ProductStatus).SetTitle(@Localizer["Page.产品状态"].Value),
                this.MakeGridHeader(x => x.Product_Notes).SetTitle(@Localizer["_Admin.Remark"].Value),

                this.MakeGridHeaderAction(width: 200)
            };
        }

        
        public override IOrderedQueryable<Product_View> GetSearchQuery()
        {
            var query = DC.Set<Product>()
                
                .CheckContain(Searcher.ProductCode, x=>x.ProductCode)
                .CheckContain(Searcher.ProductName, x=>x.ProductName)
                .CheckContain(Searcher.ProductVersion, x=>x.ProductVersion)
                .CheckEqual(Searcher.Product_Type, x=>x.Product_Type)
                .CheckEqual(Searcher.IsVulnerable, x=>x.IsVulnerable)
                .CheckContain(Searcher.ProductStatus, x=>x.ProductStatus)
                .CheckContain(Searcher.Notes, x=>x.Notes)
                .Select(x => new Product_View
                {
				    ID = x.ID,
                    
                    Product_ProductCode = x.ProductCode,
                    Product_ProductName = x.ProductName,
                    Product_ProductVersion = x.ProductVersion,
                    Product_Product_Type = x.Product_Type,
                    Product_IsVulnerable = x.IsVulnerable,
                    Product_ProductStatus = x.ProductStatus,
                    Product_Notes = x.Notes,
                })
                .OrderBy(x => x.ID);
            return query;
        }

        
    }
    public class Product_View: Product
    {
        
        public string Product_ProductCode { get; set; }
        public string Product_ProductName { get; set; }
        public string Product_ProductVersion { get; set; }
        public ProductTypeEnum? Product_Product_Type { get; set; }
        public bool? Product_IsVulnerable { get; set; }
        public string Product_ProductStatus { get; set; }
        public string Product_Notes { get; set; }

    }

}